#pragma once
#ifndef myApplication_h__
#define myApplication_h__


#include "./myEventManager.h"
#include "./myResManager.h"
#include "./myWindowlet.h"
#include "./myWinManager.h"
#include "./myMessage.h"
#include "../inc/skyPainter.h"
#include "../inc/skyInput.h"
#include "../inc/skyApplication.h"
#include "../inc/skyTimeCounter.h"

namespace Sky
{
	using namespace Sky;
	class myMsgMgr;
	class myResMgr;
	class myWinMgr;
	
	class myApplet : public Handler
	{
		DECL_RTTI1(myApplet,Handler);
	public:
		virtual Bool			init();
		virtual Void			unInit(){mApp.Finalise(&mSetting); return ;};
		myApplet():Handler(){}
		//////////////////////////////////////////////////////////////////////////
		
		MsgStatus			sendSessionEvent(myMsgMgr* mgr,Msg* event){return vContinue;}
		MsgStatus			sendWindowsEvent(myMsgMgr* mgr,Msg* event){return vContinue;}
		MsgStatus			sendNetworkEvent(myMsgMgr* mgr,Msg* event){return vContinue;}
		MsgStatus			sendSystemEvent(myMsgMgr* mgr,Msg* event){return vContinue;}

		MsgStatus			handleSendEvent(myMsgMgr* sender,Msg* event);
		MsgStatus			handlePostEvent(myMsgMgr* sender,Msg* event){return vContinue;}
		MsgStatus			handleInput(myMsgMgr* mgr,Msg* event);
		MsgStatus			handleCreated(myMsgMgr* mgr,Msg* event){return vContinue;};
		MsgStatus			handleUISize(myMsgMgr* mgr,Msg* event){return vContinue;};
		MsgStatus			handleDeleted(myMsgMgr* mgr,Msg* event);;

		virtual TreeMgr&  		getTreeMgr(){return m_Managers;};
		virtual myWinMgr&  		getWindowMgr(){return m_WinManager;};
		virtual myMsgMgr&		getEventMgr(){return m_EventManager;};
		virtual myResMgr&		getResMgr(){return m_ResManager;};

		Painter*					attachPainter(Painter* painter){mPainter = painter;return painter;}
		Painter*					detachPainter(){Painter* p = mPainter;mPainter = vNull;return p;}
		Setting&					getSetting(){return mSetting;}
		TimeCounter&				getTimeCounter(){return mTimeCouner;}
		Painter*					getPainter(){return mPainter;}
	protected:
		virtual MsgStatus			onSendEvent(myMsgMgr* sender,Msg* event);
		virtual MsgStatus			onDeleted(myMsgMgr* sender,Msg* event);
		virtual MsgStatus			onInput(myMsgMgr* mgr,Msg* event);;
	protected:
		TreeMgr		m_Managers;
		//
		myWinMgr	m_WinManager;
		//
		myMsgMgr	m_EventManager;
		//
		myResMgr	m_ResManager;
		//
		//myNetMessager	m_NetMessager;
		//
		Sky::Painter*	mPainter;
		//
		Sky::Setting    mSetting;

		Sky::Application mApp;

		Sky::TimeCounter mTimeCouner;

	};


	

	class myAppMessage : public Msg
	{
		DECL_RTTI1(myAppMessage,Msg);
		DECL_MESSAGE(myApplet,myAppMessage,Msg);
	};
	typedef RefPtr<myAppMessage> myAppMessagePtr;
}

#endif // myApplet_h__
